/// Wiki站点模型 - 支持双语配置
/// Wiki Site Model - Support bilingual configuration
class WikiSite {
  final String id;
  final String name;
  final String nameZh;  // 中文名称 Chinese name
  final String nameEn;  // 英文名称 English name
  final String baseUrl;
  final String searchUrl;
  final String description;
  final String iconPath;
  final String iconUrl;  // 远程图标URL Remote icon URL
  final String category;
  final List<String> searchKeywords;  // 搜索关键词 Search keywords

  WikiSite({
    required this.id,
    required this.name,
    required this.nameZh,
    required this.nameEn,
    required this.baseUrl,
    required this.searchUrl,
    required this.description,
    required this.iconPath,
    this.iconUrl = '',
    required this.category,
    this.searchKeywords = const [],
  });

  factory WikiSite.fromJson(Map<String, dynamic> json) {
    return WikiSite(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      nameZh: json['nameZh'] ?? json['name'] ?? '',
      nameEn: json['nameEn'] ?? json['name'] ?? '',
      baseUrl: json['baseUrl'] ?? json['url'] ?? '',
      searchUrl: json['searchUrl'] ?? '',
      description: json['description'] ?? '',
      iconPath: json['iconPath'] ?? '',
      iconUrl: json['iconUrl'] ?? '',
      category: json['category'] ?? '',
      searchKeywords: List<String>.from(json['searchKeywords'] ?? []),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'nameZh': nameZh,
      'nameEn': nameEn,
      'baseUrl': baseUrl,
      'searchUrl': searchUrl,
      'description': description,
      'iconPath': iconPath,
      'iconUrl': iconUrl,
      'category': category,
      'searchKeywords': searchKeywords,
    };
  }

  WikiSite copyWith({
    String? id,
    String? name,
    String? nameZh,
    String? nameEn,
    String? baseUrl,
    String? searchUrl,
    String? description,
    String? iconPath,
    String? iconUrl,
    String? category,
    List<String>? searchKeywords,
  }) {
    return WikiSite(
      id: id ?? this.id,
      name: name ?? this.name,
      nameZh: nameZh ?? this.nameZh,
      nameEn: nameEn ?? this.nameEn,
      baseUrl: baseUrl ?? this.baseUrl,
      searchUrl: searchUrl ?? this.searchUrl,
      description: description ?? this.description,
      iconPath: iconPath ?? this.iconPath,
      iconUrl: iconUrl ?? this.iconUrl,
      category: category ?? this.category,
      searchKeywords: searchKeywords ?? this.searchKeywords,
    );
  }

  @override
  String toString() {
    return 'WikiSite{id: $id, name: $name, baseUrl: $baseUrl}';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is WikiSite &&
          runtimeType == other.runtimeType &&
          id == other.id;

  @override
  int get hashCode => id.hashCode;
}

